# -*- coding:utf-8 -*-
from utils import publicmethod, datagetter
from pages import BaiduMainPage
import unittest, time, sys
sys.path.append("..")



class baidutest(unittest.TestCase):

    def setUp(self):
        self.driver = publicmethod.PublicMethod()
        self.driver.wd.implicitly_wait(30)
        self.driver.max_window()

    def test_01_search_Selenium(self):
        self._search_content(u'Selenium', u'Selenium_百度搜索')

    def test_02_search_by_data(self):
        datas = datagetter.get_xlsx_to_list('search.xlsx')
        print datas
        for data in datas:
            self._search_content(*data)

    def tearDown(self):
        self.driver.quit()

    def _search_content(self, text, expected, description=None):
        driver = self.driver
        baidu_page = BaiduMainPage.BaiduPage(driver)
        if description is None:
            pass
        else:
            print 'case description: ', description
        driver.open_link(baidu_page.test_url)
        baidu_page.input_search_text(text)
        baidu_page.click_search_button()
        time.sleep(2)
        self._verify_text(expected)

    def _verify_text(self, expacted):
        actual_text = self.driver.get_title()
        expact_text = expacted
        if actual_text == expact_text:
            print 'PASS-----', 'Actual Result:', actual_text
        else:
            print 'FAIL-----', 'Expect Result:', expact_text, '***Actual Result:', actual_text

if __name__ == "__main__":
    suite = unittest.TestSuite()
    suite.addTest(baidutest('test_01_search_Selenium'))
    suite.addTest(baidutest('test_02_search_by_data'))
    unittest.TextTestRunner().run(suite)